<template>
  <div class="page-root">
    <BasePanel>
        <a-button type="primary" @click="back">
            返回
        </a-button>
      <a-tabs class="tabs-wrap" v-model="tabIndex">
        <a-tab-pane key="0" tab="产品详情">
          <div class="details_box">
            <div class="details_box_right">
              <div class="details_box_right_img">
                <img :src="processImage(detailsInfo.image)" alt="" />
                <!-- <div class="extend">
                  <div></div>
                  <span>已有{{detailsInfo.anchor_no_num}}位分销者参与该推广</span>
                </div> -->
              </div>
              
            </div>
            <div class="details_box_left">
             
              <div class="task_name">
                产品名称：{{ detailsInfo.title }}
              </div>
              <div class="task_name">
                店铺名称：{{ detailsInfo.seller_nick_name }}
              </div>
              <!-- <div class="task_name">店铺名称：好运来旗舰店</div> -->
              <div class="scale_saleroom_box">
                <div class="scale_box">
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.price-0 }}</span><span>元</span></p>
                    <p>价格</p>
                  </div>
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.commission_rate-0 }}</span><span>%</span></p>
                    <p>公开达人佣金</p>
                  </div>
                  <div class="mission_subsidy">
                    <p><span>{{ detailsInfo.open_service_charge-0 }}</span><span>%</span></p>
                    <p>任务服务费</p>
                  </div>
                </div>
                
              </div>
              <div class="task_name">产品ID: {{ detailsInfo.goods_id }} <span @click="copyText(detailsInfo.goods_id)">复制</span> </div>
              <div class="custom_box">
                <div>是否控佣：<span>{{ detailsInfo.custom_commission_control === 1 ? '专属控佣' : '专属不控佣' }}</span></div>
                <div>专属佣金：<span>{{ detailsInfo.exclusive_commission_rate }}%</span></div>
                <div>专属服务费：<span>{{ detailsInfo.exclusive_service_charge_rate }}%</span></div>
              </div>
              <div class="task_btn">
                
                <div class="get_task"  @click="get_task(1)">申请样品</div>
                <!-- <div class="share_tasks">分享任务</div> -->
              </div>
            </div>
          </div>
          <div class="details_tip">产品手卡</div>
          <div class="details_tips" v-html="detailsInfo.content">
            
          </div>
        </a-tab-pane>
      </a-tabs>
    </BasePanel>
    <FormModal1 :visible="formShow1" :default="defaultObj1" :task_uuid="task_id" @success="successForm1"  @close="closeForm1" :detailsInfo="detailsInfo" :good_ID="good_ID" />
    <FormModal2 :visible="formShow2" :default="defaultObj2" :task_uuid="task_id" @success="successForm2"  @close="closeForm2" :detailsInfo="detailsInfo" />
  </div>
</template>
  
  <script>
import {mapState, mapGetters } from "vuex";
import * as Ajax from "@/api/channel";
import FormModal1 from '../mission-hall/form1';
import FormModal2 from '../mission-hall/form2';
export default {
  components: {
    FormModal1,
    FormModal2
  },
  data() {
    return {
      tabIndex: "0",
      detailsInfo: {},
      formShow: false,
      defaultObj: {},
      task_id: "",
      formShow1: false,
      defaultObj1: {},
      formShow2: false,
      defaultObj2: {},
      good_ID:''
    };
  },
  computed: {
    ...mapGetters("user", ["getCdnUrl"]),
    ...mapState('missionHall', ['detailsShow', 'task_uuid','good_id']),
  },
  created() {
    // this.task_uuid = this.$route.query.task_uuid;
    this.task_id = this.task_uuid
    this.tableInit();
  },
  methods: {
    //图片校验方法
    processImage(imageUrl) {

      if (imageUrl === undefined || imageUrl === null) {
        return ""; // 或者返回一个默认的 URL
      }

      if (!imageUrl.startsWith("http")) {
        return this.getCdnUrl + imageUrl;
      }
      return imageUrl;
    },
    updateTable(params = {}) {
      this.searchForm = { ...params };
      this.pageKey = this.$options.data().pageKey;
      this.tableInit();
    },
    // 当天日期
    getFormattedDate(type) {
      const today = new Date();
      const year = today.getFullYear();
      const month = String(today.getMonth() + 1).padStart(2, "0");
      const day = String(today.getDate()).padStart(2, "0");

      if (type === "start") {
        return `${year}-${month}-${day} 00:00:00`;
      } else if (type === "end") {
        return `${year}-${month}-${day} 23:59:59`;
      }
    },
    // table 初始化
    tableInit() {
      this.loading = true;

      Ajax.goodsList(this.good_id)
        .then((res) => {
          if (res.error === 0) {
            this.detailsInfo = res.data;
            this.good_ID = res.data.id;
          }
        })
        .finally(() => {
          this.loading = false;
        });
    },
    back() {
      this.$emit('back');
    },
    async copyText(vla) {
      try {
        await navigator.clipboard.writeText(vla);
        this.$message.success('复制成功');
      } catch (err) {
        // console.error('复制到剪贴板失败', err);
        this.$message.success('复制失败');
      }
    },
    successForm() {
      this.tableInit();
      this.closeForm();
      this.formShow1 = true;
    },
    successForm1() {
      this.closeForm1();
    },
    successForm2() {
      this.closeForm2();
    },
    closeForm() {
      this.formShow = false;
      this.defaultObj = {};
    },
    closeForm1() {
      this.formShow1 = false;
      this.defaultObj1 = {};
    },
    closeForm2() {
      this.formShow2 = false;
      this.defaultObj2 = {};
    },
    get_task(value) {
      if (value == -1) {
        this.formShow = true;
      }else if(value == 1){
        this.formShow1 = true;
      }else {
        this.formShow2 = true;
      }
    },
  },
};
</script>
<style>
.details_tips img {
  height: 426px;
}
.details_tips p {
  margin: 0;
}

</style>
  
<style lang="scss" scoped>
.details_box {
  display: flex;
  .details_box_right {
    .details_box_right_img {
      position: relative;
      width: 228px;
      height: 228px;
      border-radius: 12px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 12px;
        object-fit: contain;
      }
      .extend {
        position: absolute;
        top: 6px;
        left: 6px;
        display: flex;
        align-items: center;
        width: 163px;
        height: 26px;
        border-radius: 4px;
        background: rgba(0, 0, 0, 0.4);
        div {
          width: 5px;
          height: 5px;
          background: #ffffff;
          border-radius: 50%;
          margin:0 6px;
        }
        span {
          font-weight: 400;
          font-size: 12px;
          color: #ffffff;
        }
      }
    }
    .mission_subsidy {
      width: 228px;
      margin-top: 14px;
      text-align: center;
      font-weight: 400;
      font-size: 14px;
      color: #666666;
      span {
        font-weight: 600;
        font-size: 14px;
        color: #e33b35;
      }
      span:nth-child(2) {
        font-weight: 600;
        font-size: 20px;
        color: #e33b35;
      }
    }
  }
  .details_box_left {
    margin-left: 12px;
    .saleroom {
      width: 194px;
      height: 24px;
      background: linear-gradient(
        270deg,
        rgba(255, 255, 255, 0) 0%,
        #ffe193 100%
      );
      border-radius: 4px;
      display: flex;
      align-items: center;
      padding: 6px;
      margin-bottom: 8px;
      img {
        width: 13px;
        height: 13px;
        margin-right: 4px;
      }
      span {
        font-weight: 400;
        font-size: 13px;
        color: #9b4309;
      }
      span:nth-child(3) {
        font-weight: 600;
        font-size: 10px;
        color: #9b4309;
      }
      span:nth-child(4) {
        font-weight: 600;
        font-size: 13px;
        color: #9b4309;
      }
    }
    .task_name {
      font-weight: 400;
      font-size: 14px;
      color: #000000;
      margin-bottom: 8px;
      span {
        font-weight: 400;
        font-size: 14px;
        color: #1890FF;
        cursor: pointer;
      }
    }
    .custom_box {
      width: 407px;
      height: 30px;
      background: #F5F5F5;
      border-radius: 6px;
      display: flex;
      align-items: center;
      justify-content: space-around;
      font-weight: 400;
      font-size: 14px;
      color: #666666;
      span {
        font-weight: 400;
        font-size: 14px;
        color: #000;
      }
    }
    .scale_saleroom_box {
      display: flex;
      margin-bottom: 8px;
      .scale_box,
      .saleroom_box {
        width: 360px;
        // height: 57px;
        background: #f5f5f5;
        border-radius: 6px;
        margin-right: 14px;
        display: flex;
        padding: 7px 10px;
        box-sizing: border-box;
        .mission_subsidy {
          flex: 1;
          p:nth-child(1) {
            text-align: center;
            margin: 0;
            span:nth-child(1) {
              font-weight: 600;
              font-size: 14px;
              color: #000000;
            }
            span:nth-child(2) {
              font-weight: 400;
              font-size: 9px;
              color: #000000;
            }
          }
          p:nth-child(2) {
            font-weight: 400;
            font-size: 10px;
            color: #999999;
            margin: 0;
            text-align: center;
          }
        }
      }
      .saleroom_box {
        width: 240px;
        height: 57px;
        background: #f5f5f5;
        border-radius: 6px;
      }
      
    }
    .task_btn {
        display: flex;
        align-items: center;
        margin-top: 16px;
        .dedicated_task {
            width: 130px;
            height: 34px;
            background: #1890FF;
            border-radius: 6px;
            font-weight: 400;
            font-size: 15px;
            color: #FFFFFF;
            text-align: center;
            line-height: 34px;
            margin-right: 20px;
            cursor: pointer;
        }
       .get_task {
            width: 100px;
            height: 34px;
            background: #4C7AFF;
            border-radius: 6px;
            font-weight: 400;
            font-size: 15px;
            color: #FFFFFF;
            text-align: center;
            line-height: 34px;
            margin-right: 20px;
            cursor: pointer;
        }
      .share_tasks {
            width: 100px;
            height: 34px;
            border-radius: 6px;
            border: 1px solid #1890FF;
            font-weight: 400;
            font-size: 15px;
            color: #1890FF;
            text-align: center;
            line-height: 34px;
            cursor: pointer;
        }
    }
  }
}
.details_tips {
  font-family: PingFangSC, PingFang SC;
  font-weight: 400;
  font-size: 14px;
  color: #333333;
  line-height: 20px;
  text-align: left;
  font-style: normal;
  margin-top: 12px;
  p {
    img {
      height: 426px !important;
    }
  }
  
}
.details_tip {
  border-bottom: 1px solid #E5E5E5;
  font-size: 15px;
  color: #2ea9e6;
  margin-top: 10px;
  position: relative;
  padding: 10px 16px;
  &::after {
    content: "";
    position: absolute;
    width: 88px;
    height: 2px;
    background: #2ea9e6;
    left: 0;
    bottom: 0;
  }
}

</style>
  